/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package session;

import entity.MUser;
import java.util.List;
import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

/**
 *
 * @author SUNTIPARB
 */
@Stateless
public class MUserFacade extends AbstractFacade<MUser> {
    @PersistenceContext(unitName = "MedicalHub-warPU")
    private EntityManager em;
    @EJB
    private MUserFacade mUserFacade;

    protected EntityManager getEntityManager() {
        return em;
    }

    public MUserFacade() {
        super(MUser.class);
    }

    public List<MUser> findByUserId(String id) {
        return em.createNamedQuery("MUser.findById").setParameter("id", Long.parseLong(id)).getResultList();
    }

    public void EditUser(String id, String txtUsername, String txtName, String txtSurname, String chcPerm_File, String chcPerm_Log){
        MUser editUser = mUserFacade.find(Long.parseLong(id));
        editUser.setUsername(txtUsername);
        editUser.setName(txtName);
        editUser.setSurname(txtSurname);
        editUser.setPermFile(Boolean.parseBoolean(chcPerm_File));
        editUser.setPermLog(Boolean.parseBoolean(chcPerm_Log));
        em.persist(editUser);
    }
}
